package com.mldong.modules.cms.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mldong.base.CommonPage;
import com.mldong.modules.cms.dto.SitePageParam;
import com.mldong.modules.cms.dto.SiteParam;
import com.mldong.modules.cms.vo.SiteVO;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import com.mldong.modules.cms.entity.Site;
import com.mldong.modules.cms.mapper.SiteMapper;
import com.mldong.modules.cms.service.SiteService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 站点 服务实现类
 * </p>
 *
 * @author mldong
 * @since 2022-10-23
 */
@Service
public class SiteServiceImpl extends ServiceImpl<SiteMapper, Site> implements SiteService {
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean save(SiteParam param) {
        param.setId(null);
        Site Site = new Site();
        BeanUtil.copyProperties(param, Site);
        return super.save(Site);
    }

    @Override
    public boolean update(SiteParam param) {
        Site Site = new Site();
        BeanUtil.copyProperties(param, Site);
        return super.updateById(Site);
    }

    @Override
    public CommonPage<SiteVO> page(SitePageParam param) {
        IPage<SiteVO> page = param.buildMpPage();
        QueryWrapper queryWrapper = param.buildQueryWrapper();
        queryWrapper.eq("t.is_deleted",0);
        List<SiteVO> list = baseMapper.selectCustom(page, queryWrapper);
        page.setRecords(list);
        return CommonPage.toPage(page);
    }
    @Override
    public SiteVO findById(Long id) {
        return baseMapper.findById(id);
    }
}
